package cn.rongdao.jrkabao.ui.cashadvance.uicomponent;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mifengkong.frtools.util.FRString;

import java.util.List;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.deposit.SelectMonthBean;
import cn.rongdao.jrkabao.ui.deposit.popup.SelectMonthPopupUtil;

/**
 * Created by jack on 2017/7/28
 */

public class CashAdvanceTimeUIComponent extends RelativeLayout {
    public CashAdvanceTimeUIComponent(Context context) {
        super(context);
    }

    public CashAdvanceTimeUIComponent(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CashAdvanceTimeUIComponent(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private TextView tvTime;
    private TextView tvCheckMonthBill;
    private SelectMonthPopupUtil selectMonthPopupWindow;
    private List<SelectMonthBean> monthBeanList;

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        tvTime = findViewById(R.id.lcat_tv_time);
        tvCheckMonthBill = findViewById(R.id.lcat_tv_check_month_bill);
        selectMonthPopupWindow = new SelectMonthPopupUtil((Activity) getContext());
    }

    public void setTimeContent(String time) {
        if (FRString.isEmpty(time)) {
            tvTime.setText("当月");
        } else {
            tvTime.setText(time);
        }
    }

    public void setDepositText() {
        setVisibility(View.VISIBLE);
        tvCheckMonthBill.setText("近六个月账单 >");
    }

    public void setImageRes() {
        setVisibility(View.VISIBLE);
        tvCheckMonthBill.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon_calendar, 0, 0, 0);
        tvCheckMonthBill.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != monthBeanList && monthBeanList.size() > 0) {
                    selectMonthPopupWindow.showPopupWindow(tvCheckMonthBill);
                    selectMonthPopupWindow.setSelectMonthBeanList(monthBeanList);
                }
            }
        });
    }

    public void setMonthDataList(List<SelectMonthBean> monthBeanList) {
        this.monthBeanList = monthBeanList;
    }

    public void setOnMonthBillClickListener(OnClickListener onClickListener) {
        tvCheckMonthBill.setOnClickListener(onClickListener);
    }

    public void setOnSelectMonthClickListener(SelectMonthPopupUtil.OnSelectMonthClickListener onSelectMonthClickListener) {
        selectMonthPopupWindow.setOnSelectMonthClickListener(onSelectMonthClickListener);
    }
}
